<template>
  <div class="container">
    <div class="main">
      <!-- 头部表单 -->
      <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-form-item label="关键字">
          <el-input v-model="form.name" placeholder="请输入编号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="clearForm">清楚</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
      <!-- 分割线 -->
      <div class="separate">
        <p><span class="el-icon-info"></span> 共{{ total }}条记录</p>
      </div>
      <!-- 表格 -->
      <el-table :data="tableData" style="width: 100%" >
        <el-table-column fixed prop="id" label="编号" width="200">
        </el-table-column>
        <el-table-column prop="questionType" label="题型" width="100">
        </el-table-column>
        <el-table-column prop="questionIDs" label="题目编号" width="200">
          <template #default="scope">
            <el-link type="primary" v-for="(item,index) in scope.row.questionIDs" :key="index" @click="openvideo">{{item.number}}</el-link>
      </template>
        </el-table-column>
        <el-table-column prop="addTime" label="录入时间" width="150">
        </el-table-column>
        <el-table-column prop="totalSeconds" label="答题时间" width="100">
        </el-table-column>
        <el-table-column prop="accuracyRate" label="正确率" width="120">
        </el-table-column>
        <el-table-column prop="userName" label="录入人" width="120">
        </el-table-column>
        <el-table-column label="操作" width="120">
           <template slot-scope="scope">
             <el-button type="danger" icon="el-icon-delete" circle @click="del(scope.row.id)"></el-button>
          </template>

        </el-table-column>
      </el-table>
    </div>
    <!-- video -->
    <el-dialog
  title="提示"
  :visible="dialogVisible"
  width="30%"
  :before-close="handleClose">
  <span>这是一段信息</span>
  <video src="#"></video>
  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
</el-dialog>
  </div>
</template>

<script>
import { randoms, removeRandoms } from '@/api/hmmm/questions.js'
export default {
  data () {
    return {
      dialogVisible: false,
      total: 2,
      form: {
        name: ''
      },
      tableData: [
        {
          id: 'x35709858851886981854',
          questionType: '多选',
          questionIDs: [],
          addTime: '2023-05-31 17:01:04',
          totalSeconds: 2696,
          accuracyRate: 79,
          userName: '袁勇'
        }
      ],
      changeInfo: {
        id: '',
        choiceState: 0
      }
    }
  },
  methods: {

    async  getrenderList () {
      const { data } = await randoms()
      this.total = data.counts
      this.tableData = data.items
    },
    onSubmit () {
      this.tableData = this.tableData.filter(item => {
        if (item.id.includes(this.form.name)) {
          return item
        }
      })
    },
    clearForm () {
      this.getrenderList()
      this.form.name = ''
    },
    addClass () {
      console.log('add')
    },
    deleteRow (index, rows) {
      rows.splice(index, 1)
    },
    del (id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        this.tableData = this.tableData.filter(item => item.id !== id)
        this.changeInfo.id = id
        await removeRandoms(this.changeInfo)
        this.getrenderList()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch((error) => {
        console.log(error)
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    openvideo () {
      this.dialogVisible = true
    },
    handleClose (done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          this.dialogVisible = false
          done()
        })
        .catch(_ => {})
    }
  },
  created () {
    this.getrenderList()
  }
}
</script>

<style scoped lang="less">
.container {
  padding: 20px;
  .main {
    padding: 20px;
    background-color: #fff;
  }
  .separate {
    margin: 20px 0;
    width: 100%;
    height: 30px;
    background-color: #ccc;
    padding-left: 15px;
    border-radius: 5px;
    p {
      font-size: 18px;
      line-height: 30px;
    }
  }
}
</style>
